<template>
  <el-dialog v-model="dialog" :title="Title" width="60%" :before-close="handleClose">
    <div v-if="Title=='新增'">
      <div v-if="isshowNature=='Nature'">
        <AddNatureForm @editForm="editForm"></AddNatureForm>
      </div>
      <div v-if="isshowNature=='other'">
        <AddotherForm @editForm="editForm"></AddotherForm>
      </div>
    </div>
    <div v-if="Title=='编辑'">
      <EditForm :orderid="OrderIDValue" @editForm="editForm"></EditForm>
    </div>    
    <div v-if="Title=='下一步'">
      <NextFrom  :orderid="OrderIDValue" @editForm="editForm" />
    </div> 
    <div v-if="Title=='查看内容'">
  <el-form  ref="ruleFormRef" v-loading="loading" :inline="true"  :model="form" label-width="100px">
    <el-form-item label="订单创建时间:" >
      <el-col>
        <el-date-picker disabled  v-model="form.createTime" type="datetime" placeholder="选择创建时间" format="YYYY/MM/DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss " />
      </el-col>
    </el-form-item>
    <el-form-item label="订单id:" prop="orderId">
      <el-input v-model="form.orderId" disabled  />
    </el-form-item>
    <el-form-item label="当前订单状态:" >
      <el-input v-model="form.status" disabled type="textarea" style="width: 400px" />
    </el-form-item>
    <el-form-item label="备注:" >
      <el-input v-model="form.comment" disabled type="textarea" style="width: 400px" />
    </el-form-item>
  </el-form>
    </div> 
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive,defineEmits } from 'vue'
import AddNatureForm from '../../Util_Form/AddNatureForm.vue';
import AddotherForm from '../../Util_Form/AddotherForm.vue';

import EditForm from './EditForm.vue';
import NextFrom from '../../Util_Form/NextFrom.vue';
import { tbgetContent } from '/@/api/tb/tbOrder'
import {useUserStore} from "../../../../store/modules/user"
const emit = defineEmits(['updateForm'])
const OrderIDValue=ref('0')
const Title=ref<String>('')
const dialog = ref<Boolean>(false)
const form=ref([])
const Open = (query,OrderID) => {
  OrderIDValue.value=OrderID
  Title.value=query
  dialog.value = true
  if(Title.value=="查看内容") {
  getContent(OrderIDValue.value)

}
}
const handleClose = (done: () => void) => {
  done()


}
const userstore=useUserStore().userInfo
const isshowNature=ref()
const GetUserRole = async () => {
    for(let i=0;i<userstore?.roleList?.length;i++){
       if(userstore?.roleList[i].roleName=="销售主管"||userstore?.roleList[i].roleName=="销售人员"){
        isshowNature.value='Nature';
       }
       if(userstore?.roleList[i].roleName=="设计部主管"){
        isshowNature.value='other';
       }
    }
  };
  GetUserRole();
const getContent= async(params)=>{
const res=await tbgetContent({orderId: params })
form.value=res.data

}

const editForm=()=>{
    emit('updateForm')
    dialog.value = false
    OrderIDValue.value='0'
  }
defineExpose({
  Open
})


</script>

